package com.project.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.biz.CmsOrderInvoiceBiz;
import com.project.entity.CmsOrderInvoice;
import com.project.mapper.CmsOrderInvoiceMapper;
import com.project.pojo.model.CreateOrderInvoiceModel;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @Description: 发票业务层接口实现类
 * @Author: zhuchi
 * @CreateDate: 2020/10/16 22:58
 * @Version: 1.0
 */
@Service
public class CmsOrderInvoiceBizImpl extends ServiceImpl<CmsOrderInvoiceMapper, CmsOrderInvoice> implements CmsOrderInvoiceBiz {

    /**
     * 添加订单发票信息
     * @param orderInvoiceModel
     * @param orderId
     * @return
     */
    public int addOrderInvoice(CreateOrderInvoiceModel orderInvoiceModel, Long orderId){
        CmsOrderInvoice orderInvoice = new CmsOrderInvoice();
        BeanUtils.copyProperties(orderInvoiceModel, orderInvoice);
        orderInvoice.setInvoiceContent("明细");
        orderInvoice.setProductOrderId(orderId);
        orderInvoice.setState(0);//状态（0:未开具,1:已开具）

        return this.baseMapper.insert(orderInvoice);
    }

    /**
     * 根据订单号获取发票信息
     * @param orderId
     * @return
     */
    public CmsOrderInvoice getInvoiceByOrderId(Long orderId){
        QueryWrapper<CmsOrderInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_order_id", orderId);

        return this.baseMapper.selectOne(queryWrapper);
    }

}
